import { TypeOf } from "./type-of";

const getTargetElement = (target: any, defaultElement?: any) => {
  if (!target) {
    return defaultElement;
  }

  let targetElement = undefined;

  if (TypeOf.isFunction(target)) {
    targetElement = target();
  } else if ("current" in target) {
    targetElement = target.current;
  } else {
    targetElement = target;
  }

  return targetElement;
};

export { getTargetElement };
